package com.rayson.oneapi.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.rayson.oneapi.model.enums.UserRoleEnum;
import com.rayson.oneapi.util.StringUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * Author: rayson
 * Description:
 * Version: 1.0
 * Date: 2024-09-02 21:48
 */
@Data
public class User implements Serializable {

    @TableId(type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 用户账号
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户昵称
     */
    private String nickName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 用户角色：user/admin/ban
     */
    private String userRole;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 是否删除
     */
    @TableLogic
    private Integer isDelete;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;


    public static User initUser(String username, String password) {
        return initUser(username, password, UserRoleEnum.USER.getValue());
    }

    public static User initUser(String username, String password, String userRole) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setNickName("用户" + StringUtil.randomStr(6));
        user.setUserRole(userRole);
        return user;
    }

}
